<?php

class User extends FrontEnd_Controller {

    function User() {
        parent::FrontEnd_Controller();
        $this->load->model('User_m');
        $this->load->model('Produit_m');
        $this->load->helper('date');
    }
 function login(){
     $email=mysql_real_escape_string($this->input->post('email'));
      $pass=mysql_real_escape_string($this->input->post('pass'));
   if($email==""||$pass=="")echo "2";
   else {
       $query = $this->User_m->get_user($email, md5($pass));
      if ($query->num_rows > 0) {
          $login_user = $query->row();
          $utc = time();
          $data = array('last_login' => $utc);
                            $this->User_m->change_login_time($data, $login_user->id);
                            $this->session->set_userdata('display_name', $login_user->display_name);
                            $this->session->set_userdata('group_id', $login_user->group_id);
                            $this->session->set_userdata('user_id', $login_user->id);
                            $this->session->set_userdata('gravatar', $login_user->gravatar);
      
      echo "0";
       } else echo "1";
   }
 }

    function logout() {
        $this->session->unset_userdata('user_id');
        redirect($this->_data['smart_navigate_url']);
    }
}
?>